﻿public class GlobalMembersSkills_fighter : GlobalMembersGame_object
{
	// ****************************************************************************
	// * Punch And Kick -- a simple 2D Fighting Game.
	// *
	// * Copyright (C) 2013 by
	// * Liu Chao
	// *
	// * This file is part of the Punch And Kick project, and may only be used,
	// * modified, and distributed under the terms of the GPLv2.
	// *
	// * (GPLv2 is abbreviation of GNU General Public License Version 2)
	// *
	// * By continuing to use, modify, or distribute this file you indicate that you
	// * have read the license and understand and accept it fully.
	// *
	// * The Punch And Kick project is distributed in the hope that it will be
	// * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
	// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for
	// * more details.
	// *
	// * You should have received a copy of the GPLv2 along with this file. It is
	// * usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
	// * **************************************************************************

	// ****************************************************************************
	// * Punch And Kick -- 一个普通的2D格斗游戏
	// *
	// * 版权所有 (C) 2013 归属于
	// * 刘超
	// *
	// * 这个文件是 Punch And Kick 项目的一部分，并且只可以根据GPLv2许可协议来使用、
	// * 更改和发布。
	// *
	// * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
	// *
	// * 继续使用、修改或发布本文件，表明您已经阅读并完全理解和接受这个许可协议。
	// *
	// * Punch And Kick 项目是基于技术交流目的而加以散布的，但不负任何担保责任，例
	// * 如：稳定性、可玩性、趣味性等的担保，甚至没有适销性或特定用途的隐含担保，详
	// * 情请参照GPLv2许可协议。
	// *
	// * 您应已收到附随于本文件的GPLv2许可协议的副本，它通常在LICENSE.TXT文件中，如果
	// * 没有，请查看：<http://www.gnu.org/licenses/>.
	// * **************************************************************************

	// 格斗家特有技能


	//#define ATK_HUG_FRONT_PUT
	//#define ATK_HUG_BACK_PUT

	//#define XSPEED_FRONT_PUT
	//#define ZSPEED_FRONT_PUT
	//#define ZACC_FRONT_PUT

	//#define XSPEED_BOUNCE_AlternateDefinition1
	//#define XSPEED_BOUNCE
	//#define ZSPEED_BOUNCE_AlternateDefinition1
	//#define ZSPEED_BOUNCE
	//#define ZACC_BOUNCE_AlternateDefinition1
	//#define ZACC_BOUNCE

	internal static int AttackDamage_HugFrontPut(GamePlayer_ attacker, GamePlayer_ victim, int victim_state)
	{
		double damage;
		damage = attacker.property.throw_;
		damage += (victim.property.max_hp *0.05);
		return GlobalMembersGame_attack.DamageReduce(victim, victim_state, (int)damage);
	}

	internal static int AttackDamage_HugBackPut(GamePlayer_ attacker, GamePlayer_ victim, int victim_state)
	{
		double damage;
		double percent;
		damage = attacker.property.throw_;
		damage += (victim.property.max_hp *0.05);
		percent = attacker.property.max_hp - attacker.property.cur_hp;
		percent /= attacker.property.max_hp;
		damage += (damage *percent);
		return GlobalMembersGame_attack.DamageReduce(victim, victim_state, (int)damage);
	}

	internal static LCUI_BOOL CanUseHugFrontPut(GamePlayer_ player)
	{
		GamePlayer_ attacker;
		// 该技能不能给非格斗家的角色使用 
		if(player.type != (int)GamePlayerType.PLAYER_TYPE_FIGHTER)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		if (!player.control.a_attack)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		attacker = GlobalMembersSkills_common. GetTargetInCatchRange(player);
		if (attacker != null)
		{
			player.other = attacker;
			return DefineConstantsSkills_fighter.TRUE;
		}
		if(player.state != (int)(int)GamePlayerState.STATE_CATCH || !player.other)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		// 对方需要是被擒住状态 
		if(player.other.state != (int)(int)GamePlayerState.STATE_BE_CATCH)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		// 需要是面对面 
		if(GlobalMembersGame_control.GamePlayer_IsLeftOriented(player) == GlobalMembersGame_control.GamePlayer_IsLeftOriented(player.other))
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		return DefineConstantsSkills_fighter.TRUE;
	}

	internal static LCUI_BOOL CanUseHugBackPut(GamePlayer_ player)
	{
		if(player.type != (int)GamePlayerType.PLAYER_TYPE_FIGHTER)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		if (!player.control.a_attack)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		if(player.state != (int)(int)GamePlayerState.STATE_CATCH || !player.other)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		// 对方需要是背面被擒住状态 
		if(player.other.state != (int)(int)GamePlayerState.STATE_BACK_BE_CATCH)
		{
			return DefineConstantsSkills_fighter.FALSE;
		}
		// 需要是面朝同一方向 
		if(GlobalMembersGame_control.GamePlayer_IsLeftOriented(player) != GlobalMembersGame_control.GamePlayer_IsLeftOriented(player.other))
		{
				return DefineConstantsSkills_fighter.FALSE;
		}
		return DefineConstantsSkills_fighter.TRUE;
	}

	internal static void TargetAtHugFrontPutDone(LCUI_Widget_ widget)
	{
		int ret = 0;
		GamePlayer_ player;

		player = GlobalMembersGame_battle.GameBattle_GetPlayerByWidget(widget);
		GlobalMembersGame_control.GamePlayer_UnlockAction(player);
		ret = GlobalMembersGame_control.GamePlayer_SetLying(player);
		GlobalMembersGame_control.GamePlayer_LockAction(player);
		GlobalMembersGame_control.GamePlayer_StopXMotion(player);
		if(ret == 0)
		{
			GlobalMembersGame_control.GamePlayer_SetRestTimeOut(player, DefineConstantsSkills_fighter.SHORT_REST_TIMEOUT, GlobalMembersGame_control.GamePlayer_StartStand);
		}
	}

	internal static void TargetStartLying(GamePlayer_ player)
	{
		int ret;

		GlobalMembersGame_control.GamePlayer_UnlockAction(player);
		ret = GlobalMembersGame_control.GamePlayer_SetLying(player);
		GlobalMembersGame_control.GamePlayer_LockAction(player);
		GlobalMembersGame_control.GamePlayer_StopXMotion(player);
		if(ret == 0)
		{
			GamePlayer_SetRestTimeOut(player, 1000, GamePlayer_StartStand);
		}
	}

	internal static void TargetStartBounce(LCUI_Widget_ widget)
	{
		double x_speed;
		GamePlayer_ player;
		player = GlobalMembersGame_battle.GameBattle_GetPlayerByWidget(widget);
		if (GamePlayer_IsLeftOriented(player) != null)
		{
			x_speed = DefineConstantsSkills_fighter.XSPEED_BOUNCE;
		}
		else
		{
			x_speed = -DefineConstantsSkills_fighter.XSPEED_BOUNCE;
		}
		GameObject_SetXSpeed(widget, x_speed);
		GlobalMembersGame_attack.Game_RecordAttack(player.other, DefineConstantsSkills_fighter.ATK_HUG_FRONT_PUT, player, (int)GamePlayerState.STATE_HALF_LYING);
		if(player.other)
		{
			player.other.other = null;
		}
		player.other = null;
		GameObject_AtLanding(widget, DefineConstantsSkills_fighter.ZSPEED_BOUNCE, -DefineConstantsSkills_fighter.ZACC_BOUNCE, TargetAtHugFrontPutDone);
	}

	internal static void SelfAtSkillDone(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		player = GlobalMembersGame_battle.GameBattle_GetPlayerByWidget(widget);
		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockMotion(player);
		GamePlayer_SetReady(player);
	}

	internal static void HugFrontPut_AtActionUpdate(LCUI_Widget_ widget)
	{
		int z_index;
		GamePlayer_ player;
		double x;
		double y;
		double z;
		double x_speed;

		player = GlobalMembersGame_battle.GameBattle_GetPlayerByWidget(widget);
		if(!player.other)
		{
			return;
		}
		z_index = Widget_GetZIndex(player.object_);
		Widget_SetZIndex(player.other.object_, z_index-1);

		switch(GameObject_GetCurrentActionFrameNumber(widget))
		{
		case 1:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				GamePlayer_SetLeftOriented(player.other);
				x -= 30;
			}
			else
			{
				GamePlayer_SetRightOriented(player.other);
				x += 30;
			}
			GamePlayer_UnlockAction(player.other);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_HIT_FLY_FALL);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z+20);
			break;
		case 2:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				GamePlayer_SetRightOriented(player.other);
				x += 15;
			}
			else
			{
				GamePlayer_SetLeftOriented(player.other);
				x -= 15;
			}
			GamePlayer_UnlockAction(player.other);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_ROLL_UP);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z+25);
			break;
		case 3:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				GamePlayer_SetRightOriented(player.other);
				x += 25;
			}
			else
			{
				GamePlayer_SetLeftOriented(player.other);
				x -= 25;
			}
			GamePlayer_UnlockAction(player.other);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_HALF_STANCE);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z+20);
			break;
		case 4:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				GamePlayer_SetLeftOriented(player.other);
				x -= 25;
			}
			else
			{
				GamePlayer_SetRightOriented(player.other);
				x += 25;
			}
			GamePlayer_UnlockAction(player.other);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_ROLL_UP);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z+15);
			break;
		case 5:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				x_speed = -DefineConstantsSkills_fighter.XSPEED_FRONT_PUT;
				GamePlayer_SetRightOriented(player.other);
				x -= 40;
			}
			else
			{
				GamePlayer_SetLeftOriented(player.other);
				x_speed = DefineConstantsSkills_fighter.XSPEED_FRONT_PUT;
				x += 40;
			}
			GamePlayer_UnlockAction(player.other);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_HALF_LYING);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z+10);

			GameObject_SetXSpeed(player.other.object_, x_speed);
			GameObject_AtLanding(player.other.object_, -DefineConstantsSkills_fighter.ZSPEED_FRONT_PUT, -DefineConstantsSkills_fighter.ZACC_FRONT_PUT, TargetStartBounce);
			break;
		}
	}

	internal static void HugBackPut_AtActionUpdate(LCUI_Widget_ widget)
	{
		int z_index;
		GamePlayer_ player;
		double x;
		double y;
		double z;

		player = GlobalMembersGame_battle.GameBattle_GetPlayerByWidget(widget);
		if(!player.other)
		{
			return;
		}
		z_index = Widget_GetZIndex(player.object_);
		Widget_SetZIndex(player.other.object_, z_index-1);

		switch(GameObject_GetCurrentActionFrameNumber(widget))
		{
		//case 1:break;
		case 2:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				GamePlayer_SetLeftOriented(player.other);
				x += 30;
			}
			else
			{
				GamePlayer_SetRightOriented(player.other);
				x -= 30;
			}
			GamePlayer_UnlockAction(player.other);
			GameObject_AtActionDone(player.other.object_, (int)ActionType.ACTION_LYING_HIT, null);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_LYING_HIT);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z+30);
			break;
		case 4:
			x = GameObject_GetX(player.object_);
			y = GameObject_GetY(player.object_);
			z = GameObject_GetZ(player.object_);
			if (GamePlayer_IsLeftOriented(player) != null)
			{
				GamePlayer_SetLeftOriented(player.other);
				x += 35;
			}
			else
			{
				GamePlayer_SetRightOriented(player.other);
				x -= 35;
			}
			GamePlayer_UnlockAction(player.other);
			GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_HALF_LYING);
			GamePlayer_LockAction(player.other);
			GameObject_SetX(player.other.object_, x);
			GameObject_SetY(player.other.object_, y);
			GameObject_SetZ(player.other.object_, z);
				GlobalMembersGame_attack.Game_RecordAttack(player, DefineConstantsSkills_fighter.ATK_HUG_BACK_PUT, player.other, (int)GamePlayerState.STATE_HALF_LYING);
			GameObject_AtLanding(player.other.object_, -100, -DefineConstantsSkills_fighter.ZACC_JUMP, null);
			GamePlayer_SetActionTimeOut(player.other, 500, TargetStartLying);
			if(player.other)
			{
				player.other.other = null;
			}
			player.other = null;
				break;
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
		default:
			break;
		}
	}

	internal static void StartHugFrontPut(GamePlayer_ player)
	{
		int z_index;
		double x;
		double y;
		double z;

		if(!player.other)
		{
			return;
		}
		// 发动技能前，停止移动 
		GamePlayer_StopXMotion(player);
		GamePlayer_StopYMotion(player);
		// 对目标进行调整，使技能能够正常实现 
		GlobalMembersSkills_common.CommonSkill_AdjustTargetAtBeCatch(player);

		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockAction(player.other);
		GamePlayer_ChangeState(player, (int)(int)GamePlayerState.STATE_CATCH_SKILL_FA);
		GamePlayer_ChangeState(player.other, (int)GamePlayerState.STATE_ROLL_DOWN);
		GamePlayer_LockAction(player);
		GamePlayer_LockMotion(player);
		GamePlayer_LockAction(player.other);

		x = GameObject_GetX(player.object_);
		y = GameObject_GetY(player.object_);
		z = GameObject_GetZ(player.object_);
		if (GamePlayer_IsLeftOriented(player) != null)
		{
			GamePlayer_SetRightOriented(player.other);
			x -= 30;
		}
		else
		{
			GamePlayer_SetLeftOriented(player.other);
			x += 30;
		}
		GameObject_SetX(player.other.object_, x);
		GameObject_SetY(player.other.object_, y);
		GameObject_SetZ(player.other.object_, z);
		z_index = Widget_GetZIndex(player.object_);
		Widget_SetZIndex(player.other.object_, z_index-1);
		GameObject_AtActionDone(player.object_, (int)(int)ActionType.ACTION_CATCH_SKILL_FA, SelfAtSkillDone);
		GameObject_AtActionUpdate(player.object_, (int)(int)ActionType.ACTION_CATCH_SKILL_FA, HugFrontPut_AtActionUpdate);
		// 重置被攻击的次数 
		player.other.n_attack = 0;
	}

	internal static void StartHugBackPut(GamePlayer_ player)
	{
		int z_index;
		if(!player.other)
		{
			return;
		}
		// 发动技能前，停止移动 
		GamePlayer_StopXMotion(player);
		GamePlayer_StopYMotion(player);
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)(int)GamePlayerState.STATE_CATCH_SKILL_BA);
		GamePlayer_LockAction(player);
		GamePlayer_LockMotion(player);

		GameObject_AtActionUpdate(player.object_, (int)(int)ActionType.ACTION_CATCH_SKILL_BA, HugBackPut_AtActionUpdate);
		GameObject_AtActionDone(player.object_, (int)(int)ActionType.ACTION_CATCH_SKILL_BA, SelfAtSkillDone);

		z_index = Widget_GetZIndex(player.object_);
		Widget_SetZIndex(player.other.object_, z_index-1);
		player.other.n_attack = 0;
	}

	//* 注册格斗家特有的技能 
	public static void FighterSkill_Register()
	{
		GlobalMembersGame_skill.SkillLibrary_AddSkill(DefineConstantsSkills_fighter.SKILLNAME_HUG_FRONT_PUT, SkillPriority_AAttack.SKILLPRIORITY_MACH_A_ATTACK, CanUseHugFrontPut, StartHugFrontPut);
		GlobalMembersGame_skill.SkillLibrary_AddSkill(DefineConstantsSkills_fighter.SKILLNAME_HUG_BACK_PUT, SkillPriority_AAttack.SKILLPRIORITY_MACH_A_ATTACK, CanUseHugBackPut, StartHugBackPut);
		GlobalMembersGame_attack.AttackLibrary_AddAttack(DefineConstantsSkills_fighter.ATK_HUG_FRONT_PUT, AttackDamage_HugFrontPut, null);
		GlobalMembersGame_attack.AttackLibrary_AddAttack(DefineConstantsSkills_fighter.ATK_HUG_BACK_PUT, AttackDamage_HugBackPut, null);
	}
}
